package lxt.service.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.CostPetrolDao;
import lxt.entity.CostPetrol;
import lxt.entity.Parameter;
import lxt.service.CostPetrolService;
/**
 * 加油管理service
 * @author Lit
 *
 */
public class CostPetrolServiceImpl implements CostPetrolService {
	private CostPetrolDao costPetrolDao;
	public boolean addCostPetrol(CostPetrol costPetrol) throws Exception {
		this.costPetrolDao.save(costPetrol);
		return true;
	}

	public boolean deleteCostPetrol(String id) throws Exception {
		String[] delId = id.split(",");
		for(int i=0;i<delId.length;i++){
			String idstr = delId[i];
			this.costPetrolDao.delete(CostPetrol.class, idstr);
		}
		return true;
	}

	public int loadAllCostPetrolCount(String truckId, String driverId)
			throws Exception {
		return this.costPetrolDao.loadAllCostPetrolCount(truckId, driverId);
	}

	public List<CostPetrol> loadCostPetrol(String truckId, String driverId,
			int offset, int length) throws Exception {
		List<Object> objects = this.costPetrolDao.loadAllCostPetrol(truckId, driverId, offset, length);
		List<CostPetrol> costPetrols = new ArrayList<CostPetrol>();//定义要传出的list
		if(objects.size()>0){
			for(int i=0;i<objects.size();i++){
				Object[] ob = (Object[])objects.get(i);
				CostPetrol costPetrol = (CostPetrol)ob[0];
				Parameter par = (Parameter)ob[2];
				costPetrol.setDriverId((String)ob[1]);
				costPetrol.setPetrolType(par.getParamValue());
				costPetrols.add(costPetrol);
			}
		}
		return costPetrols;
	}

	public CostPetrol loadCostPetrolById(String id) throws Exception {
		return (CostPetrol) this.costPetrolDao.get(CostPetrol.class, id);
	}

	public boolean updateCostPetrol(CostPetrol costPetrol) throws Exception {
		this.costPetrolDao.update(costPetrol);
		return true;
	}
	/**
	 * get set
	 * @return
	 */
	public CostPetrolDao getCostPetrolDao() {
		return costPetrolDao;
	}

	public void setCostPetrolDao(CostPetrolDao costPetrolDao) {
		this.costPetrolDao = costPetrolDao;
	}

}
